<?php
/**
 * Created by PhpStorm.
 * User: times
 * Date: 2018/5/13
 * Time: 12:31
 */
namespace app\Common\model;
use think\Model;

class City extends Model
{

    protected $autoWriteTimestamp = true;
    public function add($data){
        $data['status'] = 1;
        //$data['create_time'] = time();
        return $this->save($data);
    }
    //获取一级栏目
    public function getNormalFirstCity(){
        $data = [
            'status'=> 1,
            'parent_id' => 0,
        ];

        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->select();
    }
    public function getFirstCitys($parentId = 0){
        $data = [
            'parent_id' => $parentId,
            "status" => ['neq' ,-1],
        ];

        $order = [
            'listorder' => 'desc',
            'id' => 'desc',
        ];

        $result = $this->where($data)
            ->order($order)
            ->select();
        //echo  $this->getLastSql();
        return $result;
    }

    //
    public function getNormalCitysByParentId($parentId=0) {
        $data = [
            'status' => 1,
            'parent_id' => $parentId,
        ];

        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->select();
    }

    public function getNormalCitys() {
        $data = [
            'status' => 1,
            'parent_id' => ['gt', 0],
        ];

        $order = ['id'=>'desc'];

        return $this->where($data)
            ->order($order)
            ->select();

    }

}

